package com.liyongjian.xhban.dal;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.liyongjian.xhban.model.User;
import com.liyongjian.xhban.model.UserFriend;

public interface UserFriendRepository extends PagingAndSortingRepository<UserFriend, Long> {

    @Query("select u from UserFriend t, User u where t.friendUserId=u.id and t.userId=:userId and t.state!=0 and u.state=1")
    List<User> findFriendByUserId(@Param("userId") Long userId);

    @Query("select t from UserFriend t, User u where t.friendUserId=u.id and t.userId=:userId and t.state!=0 and u.state=1")
    Page<UserFriend> findFriendByUserId(@Param("userId") Long userId, Pageable pageable);


    @Query("select t from UserFriend t where t.userId=:userId and t.friendUserId=:friendUserId and t.state!=0")
    UserFriend findByUserIdAndFriendUserId(@Param("userId") Long userId,
            @Param("friendUserId") Long friendUserId);

    @Query("select u.id from UserFriend t, User u where t.friendUserId=u.id and t.userId=:userId and t.state!=0 and u.state=1")
    List<Long> findFriendIdByUserId(@Param("userId") Long userId);

}
